<?php
class language_composition extends composite_table {
	/**
	 * Language sets table
	 *
	 * @var lang_set
	 */
	public $lang_set;
	/**
	 * Language categories table
	 *
	 * @var lang_categories
	 */
	public $lang_categories;
	/**
	 * Language parameters values table
	 *
	 * @var lang_values
	 */
	public $lang_values;
	/**
	 * Languages table
	 *
	 * @var languages
	 */
	public $languages;


	/**
	 * Constructor
	 *
	 * @param mixed $id
	 */
	public function __construct($id = null) {
		parent::__construct($id);
	}

	/**
	 * Gets slave table relations as array of query_criteria objects where key is relation table
	 *
	 * @return array
	 */
	protected function get_tables_relations() {
		$out = array();

		$criteria = new query_criteria();

		$criteria->add_custom_criterion("1 = 1");
		$out[] = new relations_wrapper($this->languages->get_table_name(), join_type::$inner, $criteria);

		$criteria->reset_criteria();
		$criteria->add_custom_criterion(sprintf("%s.%s = %s.%s",
		$this->lang_categories->get_table_name(), $this->lang_categories->lang_cat_id->get_field_name(),
		$this->lang_set->get_table_name(), $this->lang_set->lang_cat_id->get_field_name()));
		$out[] = new relations_wrapper($this->lang_categories->get_table_name(), join_type::$inner, $criteria);

		$criteria->reset_criteria();
		$criteria->add_custom_criterion(sprintf("%s.%s = %s.%s AND %s.%s = %s.%s",
		$this->lang_values->get_table_name(), $this->lang_values->lang_id->get_field_name(),
		$this->languages->get_table_name(), $this->lang_values->lang_id->get_field_name(),
		$this->lang_values->get_table_name(), $this->lang_values->lang_set_id->get_field_name(),
		$this->lang_set->get_table_name(), $this->lang_set->lang_set_id->get_field_name()));
		$out[] = new relations_wrapper($this->lang_values->get_table_name(), join_type::$left, $criteria);

		return $out;
		/*
		 SELECT *
		 FROM lang_set ls
		 INNER JOIN languages l ON 1 =1
		 INNER JOIN lang_categories lc ON lc.lang_cat_id = ls.lang_cat_id
		 LEFT JOIN lang_values lv ON lv.lang_set_id = ls.lang_set_id
		 AND lv.lang_id = l.lang_id
		 ORDER BY `l`.`lang_id` ASC
		 LIMIT 0 , 30
		 */
	}
}
?>